package com.example.mapping.controller;

import com.example.mapping.common.core.ResultResponse;
import com.example.mapping.manage.execute.StandardFlowExecute;
import com.example.mapping.utils.JacksonUtils;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 执行器controller类
 *
 * @author baoyoujia
 */
@RestController
@RequestMapping("/exec")
public class ExecutorController {

    @Autowired
    private StandardFlowExecute standardFlowExecute;

    @GetMapping(value = "/test", produces = "application/json")
    public ResultResponse<ObjectNode> test(HttpServletRequest request) throws Exception {
        String reqJson = IOUtils.toString(request.getReader());
        String execute = standardFlowExecute.execute(reqJson);
        return ResultResponse.buildSuccess(JacksonUtils.parseObject(execute, ObjectNode.class));
    }
}
